# -*- coding: utf-8 -*-
# author: sixmillions
# date: 2022/3/16

# 字符串运算

# 拼接
print("hello" + "world")  # helloworld
print("hello" "world")  # helloworld
# 默认是一个空格分割（使用逗号分割参数），可以点进去看源码
print("hello", "world")  # hello world
# 指定分割符
print("hello", "world", sep="-----")  # hello-----world
# 重复n次
print('hello ' * 3)  # hello hello hello

# 单个字符获取
a = "hello"
print(a[0])  # h
# 复数从后面开始索引
print(a[-1])  # o

# 截取（从后向前的索引是负数，从前向后是0开始）
b = '0123456789'
print(b[1:4])  # 123
print(b[1:])  # 123456789
print(b[1:-1])  # 12345678
print(b[1:8:2])  # 1357
print(b[8:1:2])  # 空
print(b[1:-3:2])  # 135
print(b[1::2])  # 13579
print(b[2:5:-1])  # 空
print(b[5:2:-1])  # 543
print(b[5:2:-2])  # 53
print(b[2::-1])  # 210
print(b[-3:])  # 789
print(b[-3::-1])  # 76543210
print(b[:-4])  # 012345
# 翻转字符串
print(b[-1::-1])  # 9876543210

# 判断元素存在
print('2' in b)  # True
print('A' not in b)  # True

# Python 字符串不能被改变。向一个索引位置赋值，比如word[0] = 'm'会导致错误
# b[1] = 's'  # 'str' object does not support item assignment

# 查看长度
print(len(b))  # 10
# 最大最小素，根据asc码表
print(max(b))  # 9
print(min(b))  # 0
# 查看asc码表对应的值
print(ord("0"))
print(ord("9"))

# list变为str
list = ['a', 'b', 'c', 'd']
print(list)  # ['a', 'b', 'c', 'd']
print(';'.join(list))  # a;b;c;d
